summaryrefslogtreecommitdiff
path: root/src/astbranch.cpp
blob: e506d9c082b8b7e005c7c051c9fa9304705f448a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "astbranch.h"

#include <bu/formatter.h>

AstBranch::AstBranch( AstNode::Type eType ) :
	AstNode( eType ),
	pParent( NULL )
{
}

AstBranch::~AstBranch()
{
	for( NodeList::iterator i = lNodes.begin(); i; i++ )
	{
		delete *i;
	}
}

AstNode *AstBranch::addNode( AstNode *pNode )
{
	AstBranch *pBranch = dynamic_cast<AstBranch *>(pNode);
	if( pBranch )
	{
		pBranch->pParent = this;
	}
	lNodes.append( pNode );
	return pNode;
}

Bu::Formatter &operator<<( Bu::Formatter &f, const AstBranch &b )
{
	f << "(Branch " << b.getType() << ": ";
	f.incIndent();
	for( AstBranch::NodeList::const_iterator i = b.lNodes.begin();
		 i; i++ )
	{
		f << f.nl << *(*i);
	}
	f.decIndent();
	return f << f.nl << ")";
}